In [1]:
import pandas as pd
pandas series is similar to numpy array, But it suppport lots of extra functionality like Pandaseries.describe()
Basic acces is samilar to numpy arrary, it support access by index( s[5] ) or slicing ( s[5:10] ).
It also support vectorise operation and looping like numpy array.
Implemented in C so it works very fast.
In [8]:
s=pd.Series([2,3,4,5,6])
print s.describe()
Hybrid of list and python Dictionary. It map key value pair.
In [11]:
sal=pd.Series([40,12,43,56],
index=['Ram',
'Syam',
"Rahul",
"Ganesh"])
print sal
In [20]:
print sal[0]
In [21]:
print sal.loc["Syam"]
Using sal[position] is not prefered instead prefer to use sal.iloc[position] becouse Index has different meaning in series so it avoid confusion
In [19]:
print sal.iloc[3]
argmax() function return index of max value element
In [24]:
print sal.argmax()
In [25]:
print sal.loc["Ganesh"]
print sal.max()
In [27]:
a=pd.Series([1,2,3,4],
index=["a","b","c","d"])
b=pd.Series([9,8,7,6],
index=["c","d","e","f"])
print a
In [28]:
print b
In [29]:
print a+b
C,D are common in both so added correctly rest are just assign a volue NaN (Not a number)
In [35]:
res = (a+b)
print res.dropna()
In [37]:
res=a.add(b,fill_value=0)
print res
s.apply(function_name) used to apply some operation on each element.
adding 5 to each element , we can do this by simply series+5 becouse it is a vector, But lets do using this new techniqe s.apply(function)
In [39]:
print res
In [40]:
print res+5
In [41]:
def add_5(x):
return x+5
In [44]:
print res.apply(add_5)
automaticaly plot index vs data plot
In [47]:
%pylab inline
res.plot()
Out[47]: